/**
 * 
 */
function getCodePlugin() {
    var codeArr1 = ["html", "objc", "javascript", "css", "php", "csharp", "cpp", "java", "python", "ruby", "vb", "delphi", "sql", "plain"];
    var codeArr2 = ["HTML/XML", "Objective-C", "JavaScript", "CSS", "PHP", "C#", "C++", "Java", "Python", "Ruby", "Visual Basic", "Delphi", "SQL", "其它"];
    var opts = '';
    for (var i = 0; i < codeArr1.length; i++) {
        opts += csdn.format('<option value="{0}">{1}</option>', codeArr1[i], codeArr2[i]);
    }
    var htmlCode = '<div>编程语言: <select id="xheCodeType">' + opts + '</select></div>'
        + '<div><textarea id="xheCodeCon" rows=6 cols=40></textarea></div>'
        + '<div style="text-align:right;"><input type="button" id="xheSave" value="确定" /></div>';
    var htmlSCode = '<div><textarea id="xheSCodeCon" rows=6 cols=40></textarea></div>'
        + '<div style="text-align:right;"><a href="https://code.csdn.net/help/CSDN_Code/code_support/FAQ_6_1" style="float:left;" target=_blank>什么是CODE代码片？</a><input type="button" id="xheSSave" value="确定" /></div>';

    var codePlugin = {
    	Code: {
    		c: 'Code', t: '插入代码', h: 1, e: function () {
    			var _this = this;
    			var jTest = $(htmlCode);
    			var jSave = $('#xheSave', jTest);
    			jSave.click(function () {
    				var sel_code = $("#xheCodeType").val();
    			    //var str = csdn.format('<pre name="code" class="{0}">{1}</pre><br />', sel_code, _this.domEncode($("#xheCodeCon").val()));
    				var xheCodeConContent = $("#xheCodeCon").val()+"";
    				xheCodeConContent = xheCodeConContent.replace(/&reg/g, "&amp;reg").replace(/&copy/g, "&amp;copy");

    				var str = '<pre name="code" class="' + sel_code + '">' + _this.domEncode(xheCodeConContent) + '</pre><br />';
    				_this.loadBookmark();
    				_this.pasteHTML(str);
    				_this.hidePanel();
    				document.cookie = "postedit_code=" + sel_code + "; expires=" + function () { var d = new Date(); d.setFullYear(d.getFullYear() + 1); return d.toGMTString(); }();
    				return false;
    			});
    			_this.saveBookmark();
    			_this.showDialog(jTest);
    			var _his_code = document.cookie.match(new RegExp("(^|\s)postedit_code=([^;]*)(;|$)"));
    			if (_his_code) $('#xheCodeType').val(_his_code);
    			else $("#xheCodeType option")[0].selected = true;
    		}
    	}
		, SCode: {
			c: 'SCode', t: '引用CODE代码片', h: 1, e: function () {
				var _this = this;
				var jTest = $(htmlSCode);
				var jSave = $('#xheSSave', jTest);
				jSave.click(function () {
					var str = $("#xheSCodeCon").val();
					var cid = 0;
					var mat = new RegExp('/([a-z0-9]+).js', 'i').exec(str);
					if (mat) { cid = mat[1]; }
					else if (/^[a-z0-9]+$/i.test(str)) { cid = str; }
					if (cid) {
						str = '<div>{CSDN:CODE:' + cid + '}</div>';
						_this.loadBookmark();
						_this.pasteHTML(str);
					}
					_this.hidePanel();
					return false;
				});
				_this.saveBookmark();
				_this.showDialog(jTest);
			}
		}
    };
    return codePlugin;
}